<template>
  <div class="search">
    <el-input
    @keypress.enter.native="$emit('search')"
      v-if="showInput"
      class="search-input"
      placeholder="请输入内容"
      v-model="content"
    >
      <el-button
        :loading="loading"
        @click="$emit('search')"
        slot="append"
        icon="el-icon-search"
      ></el-button>
    </el-input>
    <el-button v-if="title" type="primary" @click="$emit('click')">{{
      title
    }}</el-button>
  </div>
</template>

<script>
export default {
  name: "Search",
  data() {
    return {
      /**
       * 搜索内容
       */
      content: "",
    };
  },
  props: {
    /**
     * 搜索图标的loading
     */
    loading: Boolean,
    /**
     * 值
     */
    value: String,
    /**
     * 按钮标题
     */
    title: String,
  },
  methods: {},
  created() {},
  mounted() {},
  components: {},
  computed: {
    /**
     * 是否显示input
     */
    showInput() {
      return typeof this.value !== "undefined";
    },
  },
  watch: {
    /**
     * 如果搜索内容有更改，则更新v-model绑定的数据
     */
    content(value) {
      this.$emit("input", value);
    },
  },
};
</script>

<style lang='less' scoped>
.search {
  margin-bottom: 15px;
  .search-input {
    width: 400px;
    margin-right: 20px;
  }
}
</style>